
import React from "react";

export default function FactorTable({ data }) {
  const rows = [
    { label: "Alpha (截距)", key: "alpha" },
    { label: "市场因子 (MKT)", key: "beta_mkt" },
    { label: "规模因子 (SMB)", key: "beta_smb" },
    { label: "账面市值比 (HML)", key: "beta_hml" },
    { label: "盈利因子 (RMW)", key: "beta_rmw" },
    { label: "投资因子 (CMA)", key: "beta_cma" },
    { label: "R²", key: "r_squared" },
    { label: "残差波动 (σ)", key: "std_resid" },
  ];

  return (
    <div className="bg-white rounded-xl shadow p-6 mt-6">
      <h2 className="text-lg font-semibold mb-4">2. 五因子暴露系数</h2>
      <table className="w-full text-sm">
        <thead>
          <tr className="border-b">
            <th className="text-left py-2">因子</th>
            <th className="text-right py-2">估计值</th>
          </tr>
        </thead>
        <tbody>
          {rows.map((r) => (
            <tr key={r.key} className="border-b">
              <td className="py-2">{r.label}</td>
              <td className="text-right py-2 font-mono">
                {data[r.key]?.toFixed(4)}
              </td>
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}
